#ifndef _FILELIST_H
#define _FILELIST_H

typedef int (*fcmphandler) (sFile *a, sFile *b);

// <-- flags for fl_get, fl_getcwd or fl_readcwd
    #define FL_STAT BIT(0)      /* uses 1 bit */
    #define FL_SORT(f) ((f)<<1) /* uses 6 bits (useless in fl_readcwd) */
// -->

// <-- flags for FL_SORT or fl_sort (flags==0 means : do nothing)
    // sort mode ? (3 bits)
    #define BY_NOTHING  (0<<0)  /* doesn't modify the list order */
    #define BY_SIZE     (1<<0)  /* sort by size */
    #define BY_MTIME    (2<<0)  /* sort by modified time */
    #define BY_NAME     (3<<0)  /* sort alphabetically */
    #define BY_HANDLER  (4<<0)  /* pass a pointer to a function of type fcmphandler as next parameter */
    // invert order ? (1 bit)
    #define INVERT      (1<<3)  /* invert the order */
    // directories position ? (2 bits)
    #define DIRS_ASFILES    (0<<4)  /* sort the directories as if they were regular files */
    #define DIRS_BEFORE     (1<<4)  /* put the directories before files (if inverted, they are yet at the start) */
    #define DIRS_AFTER      (2<<4)  /* put the directories after files (if inverted, they are yet at the end) */
// -->

sFile * fl_getcwd   (u32 flags, ...);
sFile * fl_readcwd  (u32 flags);
int     fl_sort     (sFile *fl, u32 flags, ...);
u32     fl_hash     (char *fn);
void    fl_free     (sFile *fl);

/*
 *  N.B. :
 *
 *  sFile *fl=fl_getcwd(FL_STAT | FL_SORT(BY_SIZE));    // safer 
 *      is equivalent to :
 *  sFile *fl=fl_readcwd(FL_STAT); fl_sort(fl, BY_SIZE);    // faster
 *
 *  sFile *fl=fl_getcwd(FL_STAT | FL_SORT(BY_HANDLER | DIRS_FIRST), my_handler);    // safer
 *      is equivalent to :
 *  sFile *fl=fl_readcwd(FL_STAT); fl_sort(fl, BY_HANDLER | DIRS_FIRST, my_handler);    // faster
 *
 *  sFile *fl=fl_getcwd(0);     // safer
 *      is equivalent to :
 *  sFile *fl=fl_readcwd(0);    // faster
 *
 *  (if you don't know when you must stat, use the safer method)
 */

#endif

